package com.cloudcc.mobile.presenter;

import com.cloudcc.cloudframe.util.StringUtils;
import com.cloudcc.mobile.dao.CustomerEngine;
import com.cloudcc.mobile.dao.impl.CustomerEngineImpl;
import com.cloudcc.mobile.event.CustomerEventList.ContactListEvent;
import com.cloudcc.mobile.event.CustomerEventList.CustomerListEvent;
import com.cloudcc.mobile.event.CustomerEventList.LeadListEvent;

/**
 * 联系人 潜在客户 客户 的具体操作
 * 
 * @Description: TODO()
 * @author wangzhiqiang
 * @date 2016-3-10 下午12:00:10
 * 
 */
public class CustomerPresenter extends BasePresenter {

	private CustomerEngine mEngine;

	public CustomerPresenter() {
		super();
		mEngine = new CustomerEngineImpl();
	}

	/**
	 * 根据对象名称(objectApiName) 查询出相关 的数据
	 * 
	 * @param page
	 * @param isSearch
	 * @param objectApiName
	 */
	public void queryCustomerListByType(int page, boolean isSearch,
			String objectApiName, String searchKey) {
		String expressions = generExp(isSearch, searchKey);
		if (StringUtils.equals(objectApiName, "Lead")) {// 潜在客户
			LeadListEvent event = new LeadListEvent();
			mEngine.getLeadList(page, expressions, event);
		} else if (StringUtils.equals(objectApiName, "Account")) {// 客户
			CustomerListEvent event = new CustomerListEvent();
			mEngine.getCustomerList(page, expressions, event);
		} else if (StringUtils.equals(objectApiName, "Contact")) {// 联系人
			ContactListEvent event = new ContactListEvent();
			mEngine.getContactList(page, expressions, event);
		}
	}

	private String generExp(boolean isSearch, String searchKey) {
		return isSearch ? "name like '%" + searchKey
				+ "%' ORDER BY createdate Desc"
				: "1=1 ORDER BY createdate Desc";
	}

}
